package spider.cmd;

import org.apache.commons.cli.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


public class Cmd {
	private static Logger logger = LogManager.getLogger(Cmd.class);
	public static String zk = null;
	public static String tenantIds;
	public static String startTime;
	public static int times=5;
	public static void parserCmd(String[] args) {
		Options options = new Options();
		options.addOption("h", "help", false, "Print this usage information");
		options.addOption("f", "frequency", true, "how long create data once(unit:min) default is 5min");
		options.addOption("z", "zookeeper", true, "The connection info of zk,like:master.htdata.com:2181 default use the config htiiot.zookeeper in bin/conf/zookeeper.properties");
		options.addOption("starttime", "starttime", true, "Which time you want search data start");
		CommandLine cmd=null;
		CommandLineParser parser = new BasicParser();
		try {
			cmd = parser.parse(options, args);
		} catch (org.apache.commons.cli.ParseException e1) {
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("tzDataImport", options);
			e1.printStackTrace();
			System.exit(0);
		}
		if(cmd.hasOption("h")){
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("tzDataImport", options);
			System.exit(0);
		}
		
		if(cmd.hasOption("z")){
			zk = cmd.getOptionValue("z");
			System.setProperty("htiiot.zookeeper", zk);
		}
		
		if(cmd.hasOption("f")){
			times = Integer.parseInt(cmd.getOptionValue("f"));
		}
		if(cmd.hasOption("starttime")){
			startTime = cmd.getOptionValue("starttime");
		}
		
	}

}
